import React from 'react';
import { history } from 'umi';
import { Button } from 'antd';

type IAtag = {
  children: React.ReactNode;
  onClick?: (e: React.MouseEvent<HTMLElement>) => void;
  type?: 'link' | 'text' | any;
  href?: string;
  className?: string;
  style?: React.CSSProperties;
};

const ATag = (props: any) => {
  const {
    children,
    onClick,
    type = 'link',
    href = '',
    className = '',
    style = {},
  }: IAtag = props;
  if (type === 'text') {
    return (
      <span
        className={className}
        style={{ cursor: href ? 'pointer' : 'text', ...style }}
        onClick={() => {
          history.push({
            pathname: href,
          });
        }}
      >
        {children}
      </span>
    );
  }
  if (type === 'link') {
    return (
      <Button
        className={className}
        style={{ padding: 0, ...style }}
        type={type}
        onClick={onClick}
      >
        {children}
      </Button>
    );
  }

  return (
    <Button
      className={className}
      style={{ ...style }}
      type={type}
      onClick={onClick}
    >
      {children}
    </Button>
  );
};

export default ATag;
